package com.sharefang.aproject.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;

import com.github.paolorotolo.appintro.AppIntro;
import com.sharefang.aproject.R;
import com.sharefang.aproject.fragment.SampleSlide;
import com.sharefang.aproject.utils.CheckUtil;


/**
 * 欢迎页
 *
 * @author Lei 2016年7月26日13:17:18
 */

public class GuideActivity extends AppIntro {
    private Context tag = GuideActivity.this;
    private static final String TAG = GuideActivity.class.getSimpleName();

    @Override
    public void init(@Nullable Bundle savedInstanceState) {
        addSlide(SampleSlide.newInstance(R.layout.intro1));
        addSlide(SampleSlide.newInstance(R.layout.intro2));
        addSlide(SampleSlide.newInstance(R.layout.intro3));
        addSlide(SampleSlide.newInstance(R.layout.intro4));

        setScrollDurationFactor(2);
        setFadeAnimation();
        setSkipText("跳过");
        setDoneText("完成");
    }

    @Override
    public void onDonePressed() {
        transferActivity();
    }

    public void getStarted(View view) {
        transferActivity();
    }

    /**
     * 跳转Activity
     */
    private void transferActivity() {
        Intent intent = new Intent();
        if (isLogined()) {
            intent.setClass(tag, MainActivity.class);
        } else {
            intent.setClass(tag, LoginActivity.class);
        }
        startActivity(intent);
        GuideActivity.this.finish();
    }

    @Override
    public void onSkipPressed(Fragment currentFragment) {
        transferActivity();
    }

    private boolean isLogined() {
        return CheckUtil.isLogined();
    }
}
